<template>
  <div class="moneyDetails">
    <a-table :columns="columns5" :data-source="data" :rowKey="rowKey" :pagination="pagination"
             @change="pageChange">
    </a-table>
  </div>
</template>

<script>
  import { getDealList } from "../../serves";
  import { columns5 } from "../columns";

  export default {
    name: "MoneyDetails",
    data() {
      return {
        columns5,
        data: [],
        pagination: {
          current: 1,
          total: 0,
          pageSize: 10,
          showSizeChanger: true,
          showTotal: total => `共 ${total} 条`,
          pageSizeOptions: ['10', '20', '30', '40', '50'],
        },
        lastPageSize: 10,
      }
    },
    mounted() {
      this.getDealListData()
    },
    methods: {
      pageChange(val) {
        this.pagination.pageSize = val.pageSize
        if (val.pageSize != this.lastPageSize) {
          this.pagination.current = 1
          this.lastPageSize = val.pageSize
        } else {
          this.pagination.current = val.current
        }
        this.getDealListData()
      },
      getDealListData() {
        let params = {
          pageNum: this.pagination.current,
          pageSize: this.pagination.pageSize
        }
        getDealList(params).then(res => {
          if (res.status == 200 && res.data.status.code == 200) {
            this.data = res.data.data.records
            this.pagination.total = res.data.data.total
            this.data.forEach((item) => {
              if ([4, 7, 11].indexOf(item.refType) > -1) {
                item['before'] = item.beforeCard + 'T';
                item['after'] = item.afterCard + 'T';
              } else if ([20, 21].indexOf(item.refType) > -1) {
                if (item.refType === 20 && item.type === 1) {
                  item['before'] = item.beforeLock + 'U';
                  item['after'] = item.afterLock + 'U';
                } else {
                  item['before'] = item.beforeFreeze + 'U';
                  item['after'] = item.afterFreeze + 'U';
                }
              } else if ([5, 6, 9, 12, 22].indexOf(item.refType) > -1) {
                if (item.refType === 22 && item.type === 2) {
                  item['before'] = item.beforeLock + 'U';
                  item['after'] = item.afterLock + 'U';
                } else {
                  item['before'] = item.beforeUsdt + 'U';
                  item['after'] = item.afterUsdt + 'U';
                }
              } else {
                item['before'] = item.beforeFil + 'F';
                item['after'] = item.afterFil + 'F';
              }
              if (item.type === 1) {
                item.amount = '+' + item.amount
              } else {
                item.amount = '-' + item.amount
              }
            });
          } else {
            this.$message.warning(res.data.message)
          }
        })
      },
      rowKey(record, index) {
        return index
      }
    }
  }
</script>

<style scoped>

</style>
